package com.culture.java.spring.boot.cloud.alibaba.common.base.response.result;

import com.culture.java.spring.boot.cloud.alibaba.common.base.response.code.Code;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    public static <S> Result success(S data) {
        return new Result<S>().setCode(Code.SUCCESS.getCode()).setMessage(Code.SUCCESS.getMessage()).setData(data);
    }

    public static Result success() {
        return success(null);
    }

    public static <S> Result failure(Code code, S data) {
        return new Result<S>().setCode(code.getCode()).setMessage(code.getMessage()).setData(data);
    }

    public static Result failure(Code code) {
        return failure(code, null);
    }

}
